package com.xmh.myutil.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.xmh.myutil.entity.SpendingPlanEntity;
import com.xmh.myutil.service.SpendingPlanService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author xiaominghui
 * @Date 2020-10-13 14:54:41
 */
@Api(tags = "SpendingPlanController")
@RestController
@RequestMapping(value = "/API/spendingPlan", produces = "application/json;charset=UTF-8")
@Transactional
@CrossOrigin
public class SpendingPlanController {


    @Autowired
    private SpendingPlanService spendingPlanService;

    /**
     * 保存数据接口
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "保存接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> save(@RequestBody Map<String, Object> jsonMap) throws Exception {
        SpendingPlanEntity spendingPlanParameter = new SpendingPlanEntity(jsonMap);

        return spendingPlanService.add(spendingPlanParameter);
    }

    /**
     * 根据给定数据条件删除数据，不一定根据id删除
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody Map<String, Object> jsonMap) throws Exception {
        SpendingPlanEntity spendingPlanParameter = new SpendingPlanEntity(jsonMap);

        return spendingPlanService.delete(spendingPlanParameter);
    }

    /**
     * update修改接口，根据唯一id进行修改
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> update(@RequestBody Map<String, Object> jsonMap) throws Exception {
        SpendingPlanEntity spendingPlanParameter = new SpendingPlanEntity(jsonMap);

        return spendingPlanService.update(spendingPlanParameter);
    }

    /**
     * 查找多条数据，条件可以为空，默认查找全部
     *
     * @param jsonMap <pre>
     *                	pageIndex 页数下标
     *                	pageNumber 每页数量
     *                               </pre>
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
    @ApiOperation(value = "获取列表接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> selectList(@RequestBody Map<String, Object> jsonMap) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("list", spendingPlanService.selectList(jsonMap));

        return map;
    }

    /**
     * 根据指定条件获取单条数据
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ApiOperation(value = "获取单体数据接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> get(@RequestBody Map<String, Object> jsonMap) throws Exception {
        SpendingPlanEntity spendingPlanParameter = new SpendingPlanEntity(jsonMap);

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("entity", spendingPlanService.get(spendingPlanParameter));

        return map;
    }

}
